home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / GuiLib / Task / h / GuiObject < prev    next >
Text File  |  2003-02-14  |  10KB  |  247 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #ifndef GuiObject_h
  39. #define GuiObject_h
  40.  
  41. #include "GuiToolbox.h"
  42. #include "stl:string.h"
  43. #include "GuiWimp.h"
  44.  
  45. class GuiObject
  46. {
  47.   public:
  48.     enum {ShowAsMenu=1,ShowAsSubmenu=2,ShowAsSubwindow=4}; //flags
  49.     enum {ShowTypeDefault = 0, ShowTypeFullSpec = 1, ShowTypeTopLeft =2};
  50.  
  51.     GuiObject(const char* name);
  52.     GuiObject(GuiObjectId id); // Only reference created -
  53.                                // Toolbox object not destroyed when GuiObject is deleted
  54.     virtual ~GuiObject();
  55.     
  56.     GuiObjectId      id() const                {return m_id;}
  57.     void             show(int flags, int show_type,const void* type,
  58.                           const GuiObject*  parent,
  59.                           GuiComponentId    parent_component);
  60.     void             hide();
  61.     bool             isShowing() const;
  62.  
  63.  
  64.  
  65.   protected:
  66.     int    getValue(int method_code,int fail_value=0) const;
  67.     bool   getValue(int method_code,void *value) const;
  68.     void   setValue(int method_code,int value);
  69.     void   setValue(int method_code,const void* value);
  70.     string getString(int method_code) const;
  71.     void   setString(int method_code,const char* str);
  72.  
  73.   private:
  74.     GuiObjectId m_id;
  75.     int         m_auto_delete;
  76.  
  77.     void operator=();             // no copying - not defined
  78.     GuiObject(const GuiObject&);  // no copying - not defined
  79. };
  80.  
  81. struct GuiTopLeft //returned in some toolbox events
  82. {
  83.     int           x;
  84.     int           y;
  85. };
  86.  
  87. struct GuiShowObjectBlock //returned in some toolbox events
  88. {
  89.   GuiBBox     visibleArea;
  90.   int         xscroll;
  91.   int         yscroll;
  92.   int         behind;
  93. };
  94.  
  95. struct GuiObjectAboutToBeShown : public GuiToolboxEventHeader
  96. {
  97.     int         showType;
  98.     union
  99.     {
  100.       GuiTopLeft                pos;
  101.       GuiShowObjectBlock        full;
  102.     }info;
  103. };
  104.  
  105. //********************************************************************************
  106.  
  107. class GuiWindowObject : public GuiObject
  108. {
  109.   public:
  110.     enum {ShowDefault = 0, ShowFullSpec = 1, ShowTopLeft =2};
  111.     GuiWindowObject(const char* name) : GuiObject(name) {}
  112.     GuiWindowObject(GuiObjectId id) : GuiObject(id) {}
  113.     ~GuiWindowObject();
  114.  
  115.     void        show(const GuiTopLeft& top_left,
  116.                      const GuiObject*  parent=0,
  117.                      GuiComponentId    parent_component_id=NULL_GuiComponentId);
  118.  
  119.     void        show(const GuiGetWindowStateBlock& full_spec,
  120.                      const GuiObject*  parent=0,
  121.                      GuiComponentId    parent_component_id=NULL_GuiComponentId);
  122.  
  123.     void        showCentred(int offset_x=0,int offset_y=0,
  124.                              const GuiWindowObject* centre_in_this_window=0,
  125.                              const GuiObject*       parent=0,
  126.                              GuiComponentId         parent_component_id=NULL_GuiComponentId); 
  127.  
  128.  
  129.  
  130.     void        showAsMenu(const  GuiGetWindowStateBlock& full_spec,
  131.                              const GuiObject&  parent,
  132.                              GuiComponentId    parent_component_id=NULL_GuiComponentId);
  133.  
  134.     void        showAsMenuAtPointer(const GuiObject&  parent,
  135.                                         GuiComponentId    parent_component_id=NULL_GuiComponentId,
  136.                                         const GuiTopLeft* pointer_offset=0);
  137.  
  138.     void        showAsMenuCentred(const GuiObject& parent,
  139.                                      const GuiWindowObject* centre_in_this_window=0,
  140.                                      GuiComponentId    parent_component_id=NULL_GuiComponentId);
  141.                                             
  142.   protected:
  143.     virtual GuiObjectId underlyingWindowId() const = 0;
  144.  
  145.   private:
  146.     void showAtPointer(int flags,
  147.                          const GuiObject*  parent,
  148.                          GuiComponentId    parent_component_id,
  149.                          const GuiTopLeft* offset);
  150.     void showCentred(int flags,
  151.                       int offset_x,int offset_y,
  152.                       const GuiWindowObject* centre_in_this_window,
  153.                       const GuiObject*  parent,
  154.                       GuiComponentId    parent_component_id);
  155. };
  156.  
  157.  
  158. //********************************************************************************
  159.  
  160. class GuiMenuObject : public GuiObject
  161. {
  162.   public:
  163.     GuiMenuObject(const char* name) : GuiObject(name) {};
  164.     GuiMenuObject(GuiObjectId id) : GuiObject(id) {}
  165.  
  166.     void     show(const GuiTopLeft& top_left,
  167.                   const GuiObject&  parent,
  168.                   GuiComponentId    parent_component_id=NULL_GuiComponentId);
  169.  
  170. };
  171.  
  172. //********************************************************************************
  173. //  Window Object Inlines
  174. //********************************************************************************
  175.  
  176. inline void  GuiWindowObject::show(const GuiTopLeft& top_left,
  177.                                    const GuiObject*  parent,
  178.                                    GuiComponentId    parent_component_id)
  179. {
  180.   GuiObject::show(0,GuiObject::ShowTypeTopLeft,&top_left,parent,parent_component_id);
  181. }
  182.  
  183. //********************************************************************************
  184.  
  185. inline void  GuiWindowObject::show(const GuiGetWindowStateBlock& full_spec,
  186.                                    const GuiObject*  parent,
  187.                                    GuiComponentId    parent_component_id)
  188. {
  189.   GuiObject::show(0,GuiObject::ShowTypeFullSpec,&full_spec.visibleArea,
  190.                   parent,parent_component_id);
  191. }
  192.  
  193.  
  194. //********************************************************************************
  195.  
  196. inline void  GuiWindowObject::showCentred(int offset_x,int offset_y,
  197.                                            const GuiWindowObject* centre_in_this_window,
  198.                                            const GuiObject*  parent,
  199.                                            GuiComponentId    parent_component_id)
  200. {
  201.   showCentred(0,offset_x,offset_y,
  202.                centre_in_this_window,parent,parent_component_id);
  203. }
  204.  
  205. //********************************************************************************
  206.  
  207. inline void GuiWindowObject::showAsMenu(const GuiGetWindowStateBlock& full_spec,
  208.                                           const GuiObject&  parent,
  209.                                           GuiComponentId    parent_component_id)
  210. {
  211.   GuiObject::show(GuiObject::ShowAsMenu,GuiObject::ShowTypeFullSpec,
  212.                   &full_spec.visibleArea,&parent,parent_component_id);
  213. }
  214.  
  215. //********************************************************************************
  216.  
  217. inline void  GuiWindowObject::showAsMenuAtPointer(const GuiObject&  parent,
  218.                                                       GuiComponentId    parent_component_id,
  219.                                                       const GuiTopLeft* pointer_offset)
  220. {
  221.   showAtPointer(GuiObject::ShowAsMenu,&parent,parent_component_id,pointer_offset);
  222. }
  223.  
  224. //********************************************************************************
  225.  
  226. inline void  GuiWindowObject::showAsMenuCentred(const GuiObject&  parent,
  227.                                                    const GuiWindowObject* centre_in_this_window,
  228.                                                    GuiComponentId    parent_component_id)
  229. {
  230.   showCentred(GuiObject::ShowAsMenu,0,0,
  231.                centre_in_this_window,&parent,parent_component_id);
  232. }
  233.  
  234. //********************************************************************************
  235. //  MENUOBJECT inlines
  236. //********************************************************************************
  237.  
  238. inline void GuiMenuObject::show(const GuiTopLeft& top_left,
  239.                                 const GuiObject&  parent,
  240.                                 GuiComponentId    parent_component_id)
  241. {
  242.   GuiObject::show(GuiObject::ShowAsMenu,GuiObject::ShowTypeTopLeft,
  243.                   &top_left,&parent,parent_component_id);
  244. }
  245.  
  246. #endif
  247.